package com.dreamwhale.machinery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.dao.VipArticleCollectMapper;
import com.dreamwhale.machinery.entity.VipArticle;
import com.dreamwhale.machinery.dao.VipArticleMapper;
import com.dreamwhale.machinery.entity.VipArticleCollect;
import com.dreamwhale.machinery.service.VipArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 资料库 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-06-05
 */
@Service
public class VipArticleServiceImpl extends ServiceImpl<VipArticleMapper, VipArticle> implements VipArticleService {

    @Resource
    private VipArticleMapper vipArticleMapper;

    @Resource
    private VipArticleCollectMapper vipArticleCollectMapper;

    @Override
    public List<VipArticle> selectVipArticles(Integer hot, Integer classifyId, String title,String brandId) {
        QueryWrapper<VipArticle> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_del", 2);
        if (hot != null) {
            queryWrapper.eq("is_hot", 1);
        }
        if (classifyId != null) {
            queryWrapper.eq("classify_id", classifyId);
        }
        if (title != null) {
            queryWrapper.like("title", title);
        }
        if (brandId != null) {
            queryWrapper.like("brand_id", brandId);
        }
        return vipArticleMapper.selectList(queryWrapper);
    }

    @Override
    public VipArticle selectVipArticlesById(Integer id) {

        return vipArticleMapper.selectById(id);
    }
}
